package com.example.yiwei.crm.view.activity.JYCoordingActivity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.bigkoo.pickerview.TimePickerView;
import com.example.yiwei.crm.R;
import com.example.yiwei.crm.base.baseClass;
import com.example.yiwei.crm.dao.dockDao;
import com.example.yiwei.crm.dao.managerDao;
import com.example.yiwei.crm.dao_impl.dockDaoImpl;
import com.example.yiwei.crm.dao_impl.managerDaoImpl;
import com.example.yiwei.crm.data.GetAppointment;
import com.example.yiwei.crm.entity.ApointmentEntity;
import com.example.yiwei.crm.entity.BZFLEntity;
import com.example.yiwei.crm.entity.HospitalEntity;
import com.example.yiwei.crm.entity.KSEntity;
import com.example.yiwei.crm.entity.dockingEntity;
import com.example.yiwei.crm.json.ApointmentJson;
import com.example.yiwei.crm.json.YYSpinnerJson;
import com.example.yiwei.crm.util.NetWorkUtils;
import com.example.yiwei.crm.util.SC;
import com.example.yiwei.crm.view.activity.coordinationActivity.*;
import com.example.yiwei.crm.view.activity.jtCustomer.JDcoorActivity;

import org.json.JSONException;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;


public class JYSearchAppointmentActivity extends AppCompatActivity {
    private Spinner spinner_hospital,spinner_department,spinner_disease_category,spinner_disease,
            spinner_channel_classification,spinner_channel_source;
    private TextView txt_appointment_time,txt_hospital_time,txt_appointment_time1,
            txt_hospital_time1;
    private Button btn_appointment,btn_hospital,btn_appointment1,btn_hospital1;
    private TimePickerView mpv;
    private TimePickerView mpv1;
    private TimePickerView mpv2;
    private TimePickerView mpv3;
    Date date1,date2,date3,date4;
    private List<ApointmentEntity> list;
    String appointment_time,appointment_time1;
    String hospital_time,hospital_time1;
    private SharedPreferences sp;
    private List<HospitalEntity> list1;
    int qdfl_id,qdly_id;
    private List<KSEntity> list2;
    private List<BZFLEntity> list4;
    private List<BZFLEntity> list3;
    private List<BZFLEntity> list5;
    private List<BZFLEntity> list6;
    private Spinner spinner_coor;
    private ApointmentEntity apo;
    private ImageView img_back;
    private ImageView img_luru,img_search,img_tj,img_me;
    String hospital_name,hospital_bianma,department_name,department_bianma,disease_category,disease,disease_bianma,qdfl,qdly;
    int disease_category_id,disease_id;
    private ArrayAdapter adapter ,adapter2,adapter3,adapter4,adapter5,adapter6,adapter7,adapter8;
    List<String> hospital_list,department_list,disease_category_list,disease_list,qdfl_list,qdly_list,jd_list;
    private LinearLayout linearLayout;
    private List<String> coor_name_list = new ArrayList<>();
    List<dockingEntity> coorlist= new ArrayList<>();
    String coor_name;
    int coor_id;
    private ImageView img_qk,img_qk1,img_qk2,img_qk3;
    private Button btn_commit;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_jysearch_appointment);
        spinner_coor = (Spinner) findViewById(R.id.coording_customer_search_spinner_coor);
        btn_commit = (Button) findViewById(R.id.btn_commit);
        img_qk= (ImageView) findViewById(R.id.qingkong);
        img_qk1= (ImageView) findViewById(R.id.qingkong1);
        img_qk2= (ImageView) findViewById(R.id.qingkong2);
        img_qk3= (ImageView) findViewById(R.id.qingkong3);
        img_luru= (ImageView) findViewById(R.id.item_image_lr);
        img_search= (ImageView) findViewById(R.id.item_image_cx);
        img_me= (ImageView) findViewById(R.id.item_image_w);
        img_tj= (ImageView) findViewById(R.id.item_image_tj);
        linearLayout= (LinearLayout) findViewById(R.id.search_linearLayout);
        spinner_hospital= (Spinner) findViewById(R.id.coording_appointment_search_spinner_hospital);
        spinner_department= (Spinner) findViewById(R.id.coording_appointment_search_spinner_department);
        spinner_disease_category= (Spinner) findViewById(R.id.coording_appointment_search_spinner_disease_category);
        spinner_disease= (Spinner) findViewById(R.id.coording_appointment_search_spinner_disease);
        spinner_channel_classification= (Spinner) findViewById(R.id.coording_appointment_search_channel_classification);
        spinner_channel_source= (Spinner) findViewById(R.id.coording_appointment_search_channel_source);
        txt_appointment_time= (TextView) findViewById(R.id.coording_appointment_search_txt_appointment_time1);
        txt_appointment_time1= (TextView) findViewById(R.id.coording_appointment_search_txt_appointment_time2);
        txt_hospital_time= (TextView) findViewById(R.id.coording_appointment_search_txt_hospital_time1);
        txt_hospital_time1= (TextView) findViewById(R.id.coording_appointment_search_txt_hospital_time2);
        btn_appointment= (Button) findViewById(R.id.coording_appointment_search_btn_appointment_show1);
        btn_appointment1= (Button) findViewById(R.id.coording_appointment_search_btn_appointment_show2);
        btn_hospital= (Button) findViewById(R.id.coording_appointment_search_btn_hospital_show1);
        btn_hospital1= (Button) findViewById(R.id.coording_appointment_search_btn_hospital_show2);
        img_back= (ImageView) findViewById(R.id.coording_appointment_search_img_back);
        sp = getSharedPreferences("login", Context.MODE_PRIVATE);
        //创建选择器
        mpv = new TimePickerView(this, TimePickerView.Type.YEAR_MONTH_DAY);
        //设置时间范围
        Calendar calendar = Calendar.getInstance();
        mpv.setRange(calendar.get(Calendar.YEAR) - 100, calendar.get(Calendar.YEAR) + 100);
        //插入时间
        mpv.setTime(new Date());
        //选择监听
        mpv.setOnTimeSelectListener(new TimePickerView.OnTimeSelectListener() {

            @Override
            public void onTimeSelect(Date date) {
                date1 = date;
                appointment_time=getTime(date);
                txt_appointment_time.setText(appointment_time);
            }
        });
        btn_appointment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mpv.show();
            }
        });

        //创建选择器
        mpv1 = new TimePickerView(this, TimePickerView.Type.YEAR_MONTH_DAY);
        //设置时间范围
        Calendar calendar1 = Calendar.getInstance();
        mpv1.setRange(calendar1.get(Calendar.YEAR) - 100, calendar1.get(Calendar.YEAR) + 100);
        //插入时间
        mpv1.setTime(new Date());
        //选择监听
        mpv1.setOnTimeSelectListener(new TimePickerView.OnTimeSelectListener() {

            @Override
            public void onTimeSelect(Date date) {
                date2 = date;
                appointment_time1=getTime(date);
                txt_appointment_time1.setText(appointment_time1);
            }
        });
        btn_appointment1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mpv1.show();
            }
        });
        //创建选择器
        mpv2 = new TimePickerView(this, TimePickerView.Type.YEAR_MONTH_DAY);
        //设置时间范围
        Calendar calendar2 = Calendar.getInstance();
        mpv2.setRange(calendar1.get(Calendar.YEAR) - 100, calendar2.get(Calendar.YEAR) + 100);
        //插入时间
        mpv2.setTime(new Date());
        //选择监听
        mpv2.setOnTimeSelectListener(new TimePickerView.OnTimeSelectListener() {

            @Override
            public void onTimeSelect(Date date) {
                date3 = date;
                hospital_time=getTime(date);
                txt_hospital_time.setText(hospital_time);
            }
        });
        btn_hospital.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mpv2.show();
            }
        });
        //创建选择器
        mpv3 = new TimePickerView(this, TimePickerView.Type.YEAR_MONTH_DAY);
        //设置时间范围
        Calendar calendar3 = Calendar.getInstance();
        mpv3.setRange(calendar1.get(Calendar.YEAR) - 100, calendar2.get(Calendar.YEAR) + 100);
        //插入时间
        mpv3.setTime(new Date());
        //选择监听
        mpv3.setOnTimeSelectListener(new TimePickerView.OnTimeSelectListener() {

            @Override
            public void onTimeSelect(Date date) {
                date4 = date;
                hospital_time1=getTime(date);
                txt_hospital_time1.setText(hospital_time1);
            }
        });
        img_qk.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        txt_appointment_time.setText("");
    }
});
        img_qk1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                txt_appointment_time1.setText("");
            }
        });
        img_qk2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                txt_hospital_time.setText("");
            }
        });
        img_qk3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                txt_hospital_time1.setText("");
            }
        });
        new Thread(new Runnable() {
            @Override
            public void run() {
                SC sc = new SC();
                JSONObject object = sc.storage(sp);
                String json = object.toString();
                dockDao dockDao = new dockDaoImpl();
                coorlist = dockDao.queryAllCoordinationMessage(baseClass.find_coordination_url + 1, json);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (coorlist!=null){
                            coor_name_list.add("");
                            for (int i3 = 0;i3<coorlist.size();i3++){
                                if (coorlist.get(i3).getDocking_mechanism()!=null&&!coorlist.get(i3).getDocking_mechanism().equals("")){
                                    coor_name_list.add(coorlist.get(i3).getDocking_mechanism()+"-"+coorlist.get(i3).getDocking_name());
                                }else{
                                    coor_name_list.add(coorlist.get(i3).getDocking_name());
                                }
                            }
                            adapter2 = new ArrayAdapter(JYSearchAppointmentActivity.this,R.layout.spinner_display_style,R.id.txtvwSpinner, coor_name_list);
                            adapter2.setDropDownViewResource(R.layout.spinner_dropdown_style);
                            spinner_coor.setAdapter(adapter2);
                            spinner_coor.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                                @Override
                                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                                    if (position!=0){
                                        coor_name = coorlist.get(position-1).getDocking_name();
                                        coor_id = coorlist.get(position-1).getDocking_id();
                                    }
                                }
                                @Override
                                public void onNothingSelected(AdapterView<?> parent) {

                                }
                            });
                        }
                    }
                });
            }
        }).start();
            img_tj.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(JYSearchAppointmentActivity.this, JDcoorActivity.class);
                    intent.putExtra("tt","tt");
                    startActivity(intent);
                    finish();

                }
            });
            img_me.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(JYSearchAppointmentActivity.this, JDcoorActivity.class);
                    intent.putExtra("me","me");
                    startActivity(intent);
                    finish();
                }
            });
            img_luru.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(JYSearchAppointmentActivity.this, JDcoorActivity.class);
                    startActivity(intent);
                    finish();
                }
            });
            img_search.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(JYSearchAppointmentActivity.this, JDcoorActivity.class);
                    intent.putExtra("ii","ii");
                    startActivity(intent);
                    finish();
                }
            });
        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        btn_hospital1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mpv3.show();
            }
        });
        new Thread(new Runnable() {
            @Override
            public void run() {
                SC sc = new SC();
                JSONObject object = sc.storage(sp);
                try {
                    object.put("UAA04",1);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                String json = object.toString();
                String result = NetWorkUtils.getCount(baseClass.find_hospital_add_yy_URL, json);
                list1=new ArrayList<HospitalEntity>();
                list1= YYSpinnerJson.getHospital(result);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        hospital_list= new ArrayList<>();
                        hospital_list.add("");
                        for (int i2=0;i2<list1.size();i2++){
                            hospital_list.add( list1.get(i2).getName());
                        }
                        adapter = new ArrayAdapter(JYSearchAppointmentActivity.this, R.layout.spinner_display_style, R.id.txtvwSpinner, hospital_list);
                        adapter.setDropDownViewResource(R.layout.spinner_dropdown_style);
                        spinner_hospital.setAdapter(adapter);
                        spinner_hospital.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                            @Override
                            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                                if (position>0){
                                    hospital_name=list1.get(position-1).getName();
                                    hospital_bianma = list1.get(position-1).getBianma();
                                }else {
                                    hospital_bianma= null;
                                }
                                if (null==hospital_name){

                                }else {
                                    new Thread(new Runnable() {
                                        @Override
                                        public void run() {
                                            SC sc = new SC();
                                            JSONObject object1 = sc.storage(sp);
                                            try {
                                                object1.put("UAA02", hospital_bianma);
                                            } catch (JSONException e) {
                                                e.printStackTrace();
                                            }
                                            String json = object1.toString();
                                            String result = NetWorkUtils.getCount(baseClass.find_KS_URL, json);
                                            list2 = YYSpinnerJson.getKS(result);
                                            runOnUiThread(new Runnable() {
                                                @Override
                                                public void run() {
                                                    department_list = new ArrayList<String>();
                                                    department_list.add("");
                                                    for (int i2 = 0; i2 < list2.size(); i2++) {
                                                        department_list.add(list2.get(i2).getName());
                                                    }
                                                    adapter2 = new ArrayAdapter(JYSearchAppointmentActivity.this, R.layout.spinner_display_style, R.id.txtvwSpinner, department_list);
                                                    adapter2.setDropDownViewResource(R.layout.spinner_dropdown_style);
                                                    spinner_department.setAdapter(adapter2);
                                                    spinner_department.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                                                        @Override
                                                        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                                                            if (position > 0) {
                                                                department_name = list2.get(position - 1).getName();
                                                                department_bianma = list2.get(position - 1).getBianma();
                                                            } else {
                                                                department_bianma = null;
                                                            }
                                                        }

                                                        @Override
                                                        public void onNothingSelected(AdapterView<?> parent) {

                                                        }
                                                    });

                                                }
                                            });
                                        }
                                    }).start();
                                }
                            }
                            @Override
                            public void onNothingSelected(AdapterView<?> parent) {

                            }
                        });
                    }
                });
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                SC sc1 = new SC();
                JSONObject object3 = sc1.storage(sp);
                String json2 = object3.toString();
                String result2 = NetWorkUtils.getCount(baseClass.find_BZFL_URL,json2);
                list3 = YYSpinnerJson.getBZFL(result2);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        disease_category_list= new ArrayList<>();
                        disease_category_list.add("");
                        for (int i2=0;i2<list3.size();i2++){
                            disease_category_list.add( list3.get(i2).getName());
                        }
                        adapter3 = new ArrayAdapter(JYSearchAppointmentActivity.this, R.layout.spinner_display_style, R.id.txtvwSpinner, disease_category_list);
                        adapter3.setDropDownViewResource(R.layout.spinner_dropdown_style);
                        spinner_disease_category.setAdapter(adapter3);
                        spinner_disease_category.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                            @Override
                            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                                if (position>0){
                                    disease_category=list3.get(position-1).getName();
                                    disease_category_id = list3.get(position-1).getId();
                                }else {
                                    disease_category_id=0;
                                }
                                if ("updata".equals(getIntent().getStringExtra("TAG"))){
                                    for (int i = 0;i<disease_category_list.size();i++){
                                        if (disease_category_list.get(i).equals(apo.getDisease_category())){
                                            spinner_disease_category.setSelection(i);
                                        }
                                    }
                                }
                                if (null==disease_category){

                                }else {
                                    new Thread(new Runnable() {
                                        @Override
                                        public void run() {
                                            SC sc = new SC();
                                            JSONObject object2 = sc.storage(sp);
                                            try {
                                                object2.put("AKB01", disease_category_id);
                                            } catch (JSONException e) {
                                                e.printStackTrace();
                                            }
                                            Log.d("a", object2.toString());
                                            String json = object2.toString();
                                            Log.d("a", json);
                                            String result = NetWorkUtils.getCount(baseClass.find_BZ_URL, json);
                                            list4 = YYSpinnerJson.getBZ(result);
                                            runOnUiThread(new Runnable() {
                                                @Override
                                                public void run() {
                                                    disease_list = new ArrayList<String>();
                                                    disease_list.add("");
                                                    for (int i2 = 0; i2 < list4.size(); i2++) {
                                                        disease_list.add(list4.get(i2).getName());
                                                    }
                                                    adapter4 = new ArrayAdapter(JYSearchAppointmentActivity.this, R.layout.spinner_display_style, R.id.txtvwSpinner, disease_list);
                                                    adapter4.setDropDownViewResource(R.layout.spinner_dropdown_style);
                                                    spinner_disease.setAdapter(adapter4);
                                                    spinner_disease.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                                                        @Override
                                                        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                                                            if (position > 0) {
                                                                disease = list4.get(position - 1).getName();
                                                                disease_id = list4.get(position - 1).getId();
                                                            } else {
                                                                disease_id = 0;
                                                            }
                                                            if ("updata".equals(getIntent().getStringExtra("TAG"))) {
                                                                for (int i = 0; i < disease_list.size(); i++) {
                                                                    if (disease_list.get(i).equals(apo.getDisease())) {
                                                                        spinner_disease.setSelection(i);
                                                                    }
                                                                }
                                                            }
                                                        }

                                                        @Override
                                                        public void onNothingSelected(AdapterView<?> parent) {

                                                        }
                                                    });
                                                }
                                            });
                                        }
                                    }).start();
                                }
                            }
                            @Override
                            public void onNothingSelected(AdapterView<?> parent) {

                            }
                        });
                    }
                });
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                SC sc1 = new SC();
                JSONObject object3 = sc1.storage(sp);
                String json2 = object3.toString();
                String result2 = NetWorkUtils.getCount(baseClass.find_QDFL_URL,json2);
                list5 = YYSpinnerJson.getQDFL(result2);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        qdfl_list= new ArrayList<>();
                        qdfl_list.add("");
                        for (int i2=0;i2<list5.size();i2++){
                            qdfl_list.add(list5.get(i2).getName());
                        }
                        adapter5 = new ArrayAdapter(JYSearchAppointmentActivity.this, R.layout.spinner_display_style, R.id.txtvwSpinner,qdfl_list);
                        adapter5.setDropDownViewResource(R.layout.spinner_dropdown_style);
                        spinner_channel_classification.setAdapter(adapter5);
                        spinner_channel_classification.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                            @Override
                            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                                if (position>0){
                                    qdfl=list5.get(position-1).getName();
                                    qdfl_id = list5.get(position-1).getId();
                                }else {
                                    qdfl_id=0;
                                }
                                if ("updata".equals(getIntent().getStringExtra("TAG"))){
                                    for (int i = 0;i<qdfl_list.size();i++){
                                        if (qdfl_list.get(i).equals(apo.getClue_channel_classification())){
                                            spinner_channel_classification.setSelection(i);
                                        }
                                    }
                                }
                                if (null==qdfl){

                                }else {
                                    new Thread(new Runnable() {
                                        @Override
                                        public void run() {
                                            SC sc = new SC();
                                            JSONObject object2 = sc.storage(sp);
                                            try {
                                                object2.put("AKC01", qdfl_id);
                                            } catch (JSONException e) {
                                                e.printStackTrace();
                                            }
                                            String json = object2.toString();
                                            String result = NetWorkUtils.getCount(baseClass.find_QD_URL, json);
                                            list6 = YYSpinnerJson.getQDLY(result);

                                            runOnUiThread(new Runnable() {
                                                @Override
                                                public void run() {
                                                    qdly_list = new ArrayList<String>();
                                                    qdly_list.add("");
                                                    for (int i2 = 0; i2 < list6.size(); i2++) {
                                                        qdly_list.add(list6.get(i2).getName());
                                                    }
                                                    adapter6 = new ArrayAdapter(JYSearchAppointmentActivity.this, R.layout.spinner_display_style, R.id.txtvwSpinner, qdly_list);
                                                    adapter6.setDropDownViewResource(R.layout.spinner_dropdown_style);
                                                    spinner_channel_source.setAdapter(adapter6);
                                                    spinner_channel_source.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                                                        @Override
                                                        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                                                            if (position > 0) {
                                                                qdly = list6.get(position - 1).getName();
                                                                qdly_id = list6.get(position - 1).getId();
                                                            } else {
                                                                qdly_id = 0;
                                                            }

                                                        }

                                                        @Override
                                                        public void onNothingSelected(AdapterView<?> parent) {

                                                        }
                                                    });
                                                }
                                            });
                                        }
                                    }).start();
                                }
                            }
                            @Override
                            public void onNothingSelected(AdapterView<?> parent) {

                            }
                        });
                    }                });
            }
        }).start();
        btn_commit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View view) {
                if (date1!=null&&date2!=null&&(date1.after(date2))){
                    Toast.makeText(JYSearchAppointmentActivity.this, "开始时间不能再结束时间之后", Toast.LENGTH_SHORT).show();
                }else if (date3!=null&&date4!=null&&(date3.after(date4))){
                    Toast.makeText(JYSearchAppointmentActivity.this, "开始时间不能再结束时间之后", Toast.LENGTH_SHORT).show();
                }else {
                    Intent intent = new Intent(JYSearchAppointmentActivity.this, JYCoordAppointActivity.class);
                    intent.putExtra("tag5", "k5");
                    intent.putExtra("KXA01",coor_id);
                    intent.putExtra("UAA02N", hospital_bianma);
                    intent.putExtra("ADD02", department_bianma);
                    if (disease_category_id != 0) {
                        intent.putExtra("AKB01", disease_category_id);
                    }
                    if (disease_id != 0) {
                        intent.putExtra("AKM01", disease_id);
                    }
                    if (qdfl_id != 0) {
                        intent.putExtra("AKC01", qdfl_id);
                    }
                    if (qdly_id != 0) {
                        intent.putExtra("AKD01", qdly_id);
                    }
                    intent.putExtra("KYA02_B", txt_appointment_time.getText().toString());
                    intent.putExtra("KYA02_E", txt_appointment_time1.getText().toString());
                    intent.putExtra("KYA09_B", txt_hospital_time.getText().toString());
                    intent.putExtra("KYA09_E", txt_hospital_time1.getText().toString());
                    startActivity(intent);
                    finish();
                }
            }
        });
    }
    public static String getTime(Date date) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        return format.format(date);
    }

}
